home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / pascalMode.tcl < prev    next >
Encoding:
Text File  |  2000-12-08  |  3.0 KB  |  92 lines

  1. # (auto-install)
  2. alpha::mode Pasc 1.0.4 dummyPascal {*.p} {thinkRefMenu toolboxRefMenu electricSemicolon electricTab electricReturn} {
  3.     set unixMode(pascal) {Pasc} 
  4. } help {
  5.     Pascal Mode provides keyword coloring and automatic line indention.
  6.     Click on this "Pascal Example.p" link for an example syntax file.
  7. }
  8.  
  9. newPref v leftFillColumn {3} Pasc
  10. newPref v wordBreak {\w+} Pasc
  11. newPref f wordWrap {0} Pasc
  12. # newPref v funcExpr {^[^ \t\(#\r/@].*\(.*\)$} Pasc
  13. # newPref v parseExpr {^[^ \t\(#\r/@].*\((.*)\)$} Pasc
  14. newPref v funcExpr {^procedure.*\(} Pasc
  15. newPref v parseExpr {^procedure[ \t]*(.*)[ \t]*\(} Pasc
  16. newPref v wordBreakPreface {\W} Pasc
  17. newPref f autoMark    0 Pasc
  18.  
  19. set pascCommentRegexp    {/\*(([^*]/)|[^*]|\r)*\*/}
  20. set pascPreRegexp        {^\#[\t ]*[a-z]*}
  21. set pascKeyWords        {
  22.     procedure function integer while with return var const unit type interface
  23.     packed record begin end boolean if else repeat for downto case to of mod 
  24.     goto file do then program or label div until set not in forward and
  25.     implementation unit
  26. }
  27. regModeKeywords -b \{ \} -c red -k blue Pasc $pascKeyWords
  28. unset pascKeyWords
  29.  
  30. # This kind of stuff is handled by Codewarrior menu etc.
  31. # hook::register saveHook modified "Pasc"
  32.  
  33. #================================================================================
  34.  
  35. proc dummyPascal {} {}
  36.  
  37. set Pasc::commentCharacters(Paragraph) [list "(* " " *)" " * "]
  38.  
  39. proc Pasc::MarkFile {} {
  40.     message "Marking File"
  41.     set pos [minPos]
  42.     set pat {^([ \t]*(program|procedure))+([\t ])+([a-zA-Z0-9]+[a-zA-Z0-9])+([;\t\r\n ])}
  43.     while {![catch {search -s -f 1 -r 1 -m 0 -i 1 $pat $pos} match]} {
  44.     set posBeg [lindex $match 0]
  45.     regexp -nocase -- $pat [getText $posBeg [lindex $match 1]] \
  46.       allofit text1 text2 text3 text4
  47.     setNamedMark $text4 $posBeg $posBeg $posBeg
  48.     set pos [nextLineStart $posBeg]
  49.     }
  50.     message ""
  51. }
  52.  
  53. proc Pasc::indentLine {} {
  54.     # get details of current line
  55.     set beg [lineStart [getPos]]
  56.     set text [getText $beg [nextLineStart $beg]]
  57.     regexp "^\[ \t\]*" $text white
  58.     set len [string length $white]
  59.     set epos [pos::math $beg + $len]
  60.     
  61.     # Find last previous non-comment line and get its leading whitespace
  62.     set pos $beg
  63.     while 1 {
  64.     if {[catch {search -s -f 0 -r 1 -i 0 -m 0 "^\[ \t\]*\[^ \t\r\n\]" [pos::math $pos - 1]} lst]} {
  65.         # search failed at top of file
  66.         set line "#"
  67.         set lwhite 0
  68.         break
  69.     }
  70.     if {![catch {text::inCommentBlock [lindex $lst 0]} res]} {
  71.         set pos [lindex $res 0]
  72.     } else {
  73.         set line [getText [lindex $lst 0] [pos::math [nextLineStart [lindex $lst 0]] - 1]]
  74.         set lwhite [posX [pos::math [lindex $lst 1] - 1]]    
  75.         break
  76.     }
  77.     }
  78.     
  79.     global indentationAmount electricColon
  80.     if {[regexp "begin\[ \t\]*$" $line]} {
  81.     incr lwhite $indentationAmount
  82.     }
  83.     if {[regexp "end;?\[ \t\r\n\]*$" [getText $epos [nextLineStart $epos]]]} {
  84.     incr lwhite [expr -$indentationAmount]
  85.     }
  86.     set lwhite [text::indentOf $lwhite]
  87.     if {$white != $lwhite} {
  88.     replaceText $beg $epos $lwhite
  89.     }
  90.     goto [pos::math $beg + [string length $lwhite]]
  91. }
  92.